<?php

namespace app\common\logic;

/**
 * 栏目逻辑
 */
class Column extends LogicBase
{

    /**
     * 获取栏目列表
     */
    public function getColumnList($where = [], $field = 'a.*', $order = '')
    {
        
        $this->modelColumn->alias('a');
        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelColumn->getList($where, $field, $order, DB_LIST_ROWS);
    }
    
    /**
     * 获取栏目列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.name|a.describe'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
     /**
     * 栏目信息编辑
     */
    public function columnEdit($data = [])
    {
        $validate_result = $this->validateColumn->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateColumn->getError()];
        }
        
        $url = url('columnList');   
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        if($handle_text == '新增'){
            
            $data['created_at'] = time();
        }
        
        $data['updated_at'] = time();
        
        $result = $this->modelColumn->setInfo($data);

        $result && action_log($handle_text, '栏目' . $handle_text . '，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, '栏目操作成功', $url] : [RESULT_ERROR, $this->modelColumn->getError()];
    }
  
     /**
     * 获取栏目信息
     */
    public function getColumnInfo($where = [], $field = 'a.*')
    {
        $this->modelColumn->alias('a');
       
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelColumn->getInfo($where, $field);
    }
    
    /**
     * 获取栏目分类列表
     */
    public function getColumnCategoryList($where = [], $field = true, $order = '', $paginate = 0)
    {
        return $this->modelColumn->getList($where, $field, $order, $paginate);
    }
}

